{% extends "admin/base_site.html" %}
{% load i18n admin_static admin_modify suit_tags admin_urls %}
{% load url from suit_compat %}

{% block extrahead %}{{ block.super }}
    {% url 'admin:jsi18n' as jsi18nurl %}
    <script type="text/javascript" src="{{ jsi18nurl|default:"../../../jsi18n/" }}"></script>

    {{ media }}

{% endblock %}


{% block extrajs %}
    {{ block.super }}

    {% if 'CONFIRM_UNSAVED_CHANGES'|suit_conf %}
        <!-- Warn on leaving unsaved form -->
        <script src="{% static 'suit/js/suit-form-confirm.js' %}"></script>
        <script type="text/javascript">
            confirmExitIfModified('{% firstof opts.model_name opts.module_name %}_form', '{% trans 'You have unsaved changes' %}.');
        </script>
    {% endif %}

    {% if adminform.model_admin.suit_form_tabs %}
        <script type="text/javascript">
            (function ($) {
                $(function () {
                    $('#suit_form_tabs').suit_form_tabs();
                });
            }(Suit.$))
        </script>
    {% endif %}

    <script>
        (function ($) {
            $(function () {
                $("#{% firstof opts.model_name opts.module_name %}_form").suit_form_debounce();
            });
        }(Suit.$))
    </script>

{% endblock %}

{% block extrastyle %}
    {{ block.super }}
{% endblock %}

{% block content_title_value %}
    {% trans 'Add' %} {{ opts.verbose_name }}
{% endblock %}

{% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %}

{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}

{% if not is_popup %}
    {% block breadcrumbs %}
        <ul class="breadcrumb">
            <li>
                <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
                <span class="divider">&raquo;</span>
            </li>
            <li>
                <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{% firstof opts.app_config.verbose_name app_label|capfirst|escape %}</a>
                <span class="divider">&raquo;</span>
            </li>
            <li>
                {% if has_change_permission %}
                    <a href="{% url opts|admin_urlname:'changelist' %}">
                        {{ opts.verbose_name_plural|capfirst }}</a>{% else %}
                    {{ opts.verbose_name_plural|capfirst }}{% endif %}
                <span class="divider">&raquo;</span>
            </li>
            <li class="active">
                {% if add %}{% trans 'Add' %} {{ opts.verbose_name }}{% else %}
                    {{ original|truncatewords:"18" }}{% endif %}
            </li>
        </ul>
    {% endblock %}
{% endif %}

{% block content %}
    <div id="content-main" class="inner-two-columns">

        <form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post"

              id="{% firstof opts.model_name opts.module_name %}_form" class="form-horizontal" novalidate>
            <input type='text' style='display: none' id='action' name='action' value='0'></input>
            <div class="inner-right-column">

                <div class="box save-box">
                    {% if is_edit is True %}
                        <button type='submit' class='btn btn-high' onclick="return setValue()">执行工具</button>
                    {% endif %}
                    {% block submit_buttons_bottom %}{% submit_row %}{% endblock %}

                </div>

                {% block object-tools %}
                    {% if change %}{% if not is_popup %}
                        <h4 class="italic-title">{% trans 'tools'|capfirst %}</h4>
                        <ul class="box menu-box">
                            {% block object-tools-items %}
                                <li>
                                    {% if '1.9'|django_version_lt %}
                                        <a href="history/" class="historylink">
                                    {% else %}
                                        {% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %}
                                        <a href="{% add_preserved_filters history_url %}" class="historylink">
                                    {% endif %}
                                    <i class="icon-time icon-alpha75"></i>{% trans "History" %}</a>
                                </li>
                                {% if has_absolute_url %}
                                    <li>
                                        <a href="{{ original.get_absolute_url }}" class="viewsitelink"><i
                                                class="icon-eye-open icon-alpha75"></i>{% trans "View on site" %}</a>
                                    </li>
                                {% endif %}

                                {% if has_add_permission %}
                                    <li>
                                        {% if '1.9'|django_version_lt %}
                                            <a href="../add/">
                                        {% else %}
                                            <a href="{% url opts|admin_urlname:'add' %}">
                                        {% endif %}
                                        <i class="icon-plus-sign icon-alpha75"></i>
                                        {% blocktrans with opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
                                        </a>
                                    </li>
                                    {# {% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}</a>#}
                                {% endif %}

                            {% endblock %}
                        </ul>
                    {% endif %}{% endif %}
                {% endblock %}

                {% block sidebar %}{% endblock %}

            </div>
            <div class="inner-center-column">
                {% csrf_token %}{% block form_top %}{% endblock %}
                {% block suit_form_tabs %}
                    {% if adminform.model_admin.suit_form_tabs %}
                        <ul id="suit_form_tabs" class="nav nav-tabs nav-tabs-suit" data-tab-prefix="suit-tab">
                            {% for tab in adminform.model_admin.suit_form_tabs %}
                                <li><a href="#{{ tab.0 }}">{{ tab.1 }}</a></li>{% endfor %}
                        </ul>
                    {% endif %}
                {% endblock %}
                <div class="tab-content tab-content-main">
                    {% if is_popup %}
                        <input type="hidden" name="_popup" value="1"/>{% endif %}
                    {% if errors %}
                        <div class="alert alert-error">
                            {% if errors|length == 1 %}{% trans "Please correct the error below." %}{% else %}
                                {% trans "Please correct the errors below." %}{% endif %}
                            {{ adminform.form.non_field_errors }}
                        </div>
                    {% endif %}

                    {# render suit_form_includes at top position #}
                    {% include 'suit/includes/change_form_includes.html' with position='top' %}

                    {% block field_sets %}
                        {% for fieldset in adminform %}
                            {% include "admin/includes/fieldset.html" %}
                        {% endfor %}
                    {% endblock %}

                    {% block after_field_sets %}{% endblock %}

                    {# render suit_form_includes at middle position #}
                    {% include 'suit/includes/change_form_includes.html' with position='middle' %}

                    {% if is_edit is True %}
                        <div class="inline-group " id="toolsexecjob_set-group">
                            <h2>目标主机</h2>
                            <div class="inline-related dynamic-toolsexecjob_set" id="toolsexecjob_set-0">
                                <h3><b>目标主机:</b>&nbsp;
                                </h3>
                                <fieldset class="module aligned first ">
                                    <div class="control-group form-row field-hosts ">
                                        <div>
                                            <div class="control-label"><label class="required"
                                                                              for="id_toolsexecjob_set-0-hosts">目标主机:</label>
                                            </div>
                                            <div class="controls">
                                                <div class="related-widget-wrapper">
                                                    <select multiple="multiple"
                                                            id="sls_hosts"
                                                            name="sls_hosts">
                                                        {% for obj in hostList %}
                                                            <option value="{{ obj.id }}">{{ obj.host_name }}</option>
                                                        {% endfor %}
                                                    </select>
                                                </div>
                                                <span class="help-inline">按住 ”Control“，或者Mac上的 “Command”，可以选择多个。</span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="control-group form-row field-param ">
                                        <div>
                                            <div class="control-label"><label
                                                    for="id_toolsexecjob_set-0-param">执行参数:</label></div>
                                            <div class="controls"><textarea class="vLargeTextField" cols="40"
                                                                            id="txt_param"
                                                                            name="txt_param"
                                                                            rows="10"></textarea></div>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                        </div>
                    {% endif %}
                </div>

                {% block after_related_objects %}{% endblock %}

                {# render suit_form_includes at last position #}
                {% include 'suit/includes/change_form_includes.html' with position='bottom' %}

                {% block admin_change_form_document_ready %}
                    <script type="text/javascript">
                        (function ($) {
                            $(document).ready(function () {
                                $('.add-another').click(function (e) {
                                    e.preventDefault();
                                    showAddAnotherPopup(this);
                                });
                                $('.related-lookup').click(function (e) {
                                    e.preventDefault();
                                    showRelatedObjectLookupPopup(this);
                                });
                                {% if adminform and add %}
                                    $('form#{% firstof opts.model_name opts.module_name %}_form :input[type!=button][type!=submit]:visible:enabled:first').focus()
                                {% endif %}
                            });
                        })(django.jQuery);
                    </script>
                {% endblock %}

                {# JavaScript for prepopulated fields #}
                {% prepopulated_fields_js %}

            </div>
        </form>
    </div>

    <script>

        function setValue() {
            if ($("#sls_hosts").find('option:selected').length > 0) {
                document.getElementById("action").value = 1;
                return true
            } else {
                alert("请选择需要执行工具的目标主机");
                return false
            }

        }

    </script>

{% endblock %}

{# Empty centered sidebar as now we use sidebar in content block#}
{% block sidebar_content %}{% endblock %}

